<template>
<div>
  <el-breadcrumb separator-class="el-icon-arrow-right">
    <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item>订单管理</el-breadcrumb-item>
    <el-breadcrumb-item>订单列表</el-breadcrumb-item>
  </el-breadcrumb>
  <el-card>
    <el-row>
      <el-col :span="6">
          <el-input
            placeholder="请输入内容">
            <el-button type="primary" slot="append" icon="el-icon-search"></el-button>
          </el-input>
      </el-col>
    </el-row>
    <el-table :data="orderList" stripe>
      <el-table-column type="index">#</el-table-column>
      <el-table-column label="订单编号" prop="number"></el-table-column>
      <el-table-column label="订单价格" prop="price"></el-table-column>
      <el-table-column label="是否付款" prop="payStatus">
        <template slot-scope="scope">
          <el-tag type="success" v-show="scope.row.payStatus">已支付</el-tag>
          <el-tag type="danger" v-show="!scope.row.payStatus">未支付</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="是否发货" prop="isSend">
        <template slot-scope="scope">
          <el-tag type="success" v-show="scope.row.sendStatus">已发货</el-tag>
          <el-tag type="danger" v-show="!scope.row.sendStatus">未发货</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="下单时间">
        <template slot-scope="scope">
          {{scope.row.createTime}}
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-edit" @click="showEditAddrDialog" v-model="scope.row"></el-button>
          <el-button type="success" icon="el-icon-location" @click="showProgressDialog"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog
      title="提示"
      :visible.sync="editAddrDialogVisible"
      width="50%" center>
      <el-form :model="addrForm" :rules="addrFormRules" ref="addrFormRef" label-width="100px">
        <el-form-item label="省市区/县" prop="addr1">
          <el-input v-model="addrForm.name"></el-input>
        </el-form-item>
        <el-form-item label="详细地址" prop="addr2">
          <el-input v-model="addrForm.name"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
    <el-button @click="editAddrDialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="editAddrDialogVisible = false">确 定</el-button>
  </span>
    </el-dialog>

<!--物流对话框-->
    <el-dialog
      title="物流信息"
      :visible.sync="progressDialogVisible"
      width="50%"
    center>
      <el-timeline>
        <el-timeline-item
          v-for="(activity, index) in activities"
          :key="index"
          :icon="activity.icon"
          :type="activity.type"
          :color="activity.color"
          :size="activity.size"
          :timestamp="activity.timestamp">
          {{activity.content}}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
  </el-card>
</div>
</template>

<script>
export default {
  name: 'Orders',
  data () {
    return {
      queryInfo: {
        query: '',
        pageNum: 1,
        pageSize: 10
      },
      orderList: [],
      total: 0,
      editAddrDialogVisible: false,
      progressDialogVisible: false,
      addrForm: {
        addr1: [],
        addr2: ''
      },
      addrFormRules: {
        addr1: [
          { required: true, message: '请选择地区', trigger: 'blur' }
        ],
        addr2: [
          { required: true, message: '请输入详细地址', trigger: 'blur' }
        ]
      },
      activities: [{
        content: '买家已支付',
        timestamp: '2018-04-12 20:46',
        size: 'large',
        type: 'primary',
        icon: 'el-icon-success',
        color: '#0bbd87'
      }, {
        content: '商家已发货',
        timestamp: '2018-04-03 20:46',
        size: 'large',
        icon: 'el-icon-success',
        type: 'primary',
        color: '#0bbd87'
      }, {
        content: '在路上',
        timestamp: '2018-04-03 20:46',
        size: 'large',
        icon: 'el-icon-location',
        color: '#0bbd87'
      }, {
        content: '买家确认收货',
        timestamp: '2018-04-03 20:46',
        size: 'large',
        icon: 'el-icon-success'
      }]
    }
  },
  created () {
    this.getOrderList()
  },
  methods: {
    async getOrderList () {
      const { data: result } = await this.$http.get('/order/getOrderList', { params: this.queryInfo })
      if (result.status !== 200) {
        return this.$message.error('查询订单列表失败！')
      }
      this.orderList = result.data.orderVO
      this.total = result.data.total
      this.$message.success('查询订单列表成功！')
    },
    showEditAddrDialog () {
      this.editAddrDialogVisible = true
    },
    showProgressDialog () {
      this.progressDialogVisible = true
    }
  }
}
</script>

<style scoped>
.el-breadcrumb {
  margin-bottom: 10px;
}
</style>
